#ifndef SSLCLIENT_H
#define SSLCLIENT_H

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <pthread.h>
#include "openssl/crypto.h"
#include "openssl/x509.h"
#include "openssl/pem.h"
#include "openssl/ssl.h"
#include "openssl/err.h"

#include <QObject>


#define	MAX_T 1
#define	CLIENTCERT	"certs/sslclientcert.pem"
#define	CLIENTKEY	"certs/sslclientkey.pem"
#define	CAFILE		"certs/cacert.pem"

class SSLClient : public QObject
{
    Q_OBJECT
public:
    explicit SSLClient(QObject *parent = nullptr);
    ~SSLClient() override;
    void Connect();

    void TestConnect();

signals:
    void printMessage(const QString& message);
private:
    void InitSSl();
    void Print(const QString& message);

private:
    int 		err,buflen,read;
    int 		sd;

    struct 		sockaddr_in dest_sin;
    int	sock;
    SSL_CTX		*ctx;
    SSL		*ssl;
    X509		*server_cert;
    char	   	*str;
    char		buf [1024];
    SSL_METHOD 	*meth;
    int		i;
    pthread_t	pid[MAX_T];
    QString server_addr;
};



#endif // SSLCLIENT_H
